/**
 * 
 */
package com.zhihu.search;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
 * @author zhoufox
 * 2015-09-25 23:28
 */
public class Crawler {
	
	 private static final Logger logger = LogManager.getLogger(Crawler.class);
	
	//链接源代码  
    private String pageSourceCode = "";  
    //返回头信息  
    private Header[] responseHeaders = null;  
    //连接超时时间  
    private static int connectTimeout = 3500;  
    //连接读取时间  
    private static int readTimeout = 3500;  
    //默认最大访问次数  
    private static int maxConnectTimes = 3;  
    //网页默认编码方式  
    private static String charsetName = "iso-8859-1";  
    private static HttpClient httpClient = new DefaultHttpClient();
    
	public static void main(String[] args) {
		CloseableHttpClient httpclient = HttpClients.createDefault();
    	HttpGet httpget = new HttpGet("http://www.baidu.com/");
    	try {
			CloseableHttpResponse response = httpclient.execute(httpget);
			 try {
	                System.out.println("----------------------------------------");
	                System.out.println(response.getStatusLine());
	                System.out.println(response.getAllHeaders());
	                logger.debug(response.getEntity());
	                // Do not feel like reading the response body
	                // Call abort on the request object
	                httpget.abort();
	            } finally {
	                response.close();
	            }
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
